import {Injectable} from '@angular/core';
import {HttpService} from "@core/http/http.service";
import {ToolsService} from "@shared/service/tools/tools.service";
import * as API from "@api/index";
// import {CommonPageVo} from "@interface/crowd.model";
// import {SNSResult} from '@interface/interface.model';
// import {SocialCircle} from "@interface/community.model";
import {Observable} from "rxjs/Rx";
import {CommonPageVo, SNSResult, SocialCircle} from "@interface/index";
// import {SNSResult} from "@interface/interface/interface.model";
//
// import {SocialCircle} from "@interface/community/community.model";
// import {CommonPageVo} from "@interface/shared/shared.model";


@Injectable()
export class CommunityService {

  constructor(public http: HttpService,
              public tool: ToolsService) {
  }

  // /**
  //  * @description 获取轮播图
  //  * @author ouyqx-691
  //  * @date 2017-12-11
  //  */
  // getSlider() {
  //   const url: string = API.AD_LIST_URL + '?adsType=banner&showPosition=46&rows=10';
  //   return this.http.get(url).map((res) => res.json());
  // };


  //   /**
  //    * @description 查询我创建的圈子
  //    * @author ouyqx-691
  //    * @date 2017-12-11
  //    */
  //   getMyCircle() {
  //     const url: string = API.CIRCLE_JOIN;
  //     return this.http.get(url).map((res) => res.json());
  //   };

  //   /**
  //  * @description 查询热门圈子
  //  * @author ouyqx-691
  //  * @date 2017-12-11
  //  */
  //   getHotCircle() {
  //     const url: string = API.CIRCLE_HOT;
  //     return this.http.get(url).map((res) => res.json());
  //   };

  /**
   * @description 查询圈子详情信息
   * @author ouyqx-691
   * @date 2017-12-12
   */
  getCircleDetailInfo(circleId: number) {
    const url: string = API.CIRCLE + '?id=' + circleId;
    return this.http.get(url).map((res) => res.json());
  };

  /**
   * @description 查询精选帖子
   * @author ouyqx-691
   * @date 2017-12-12
   */

  getChoiceFeed(params) {
    const url: string = API.SELECTION_FEED + "?" + this.tool.param(params);
    return this.http.get(url).map((res) => res.json());
  };

  /**
   * @description 获取我加入的圈子列表
   * @author zhupw1360
   * @date 2017-12-11
   */
  getCirclesJoin(params): Observable<SNSResult<CommonPageVo<SocialCircle>>> {
    const url = API.CIRCLE_JOIN + "?" + this.tool.param(params);
    return this.http.get(url).map((res) => res.json());
  }

  /**
   * @description 获取我创建的圈子
   * @author zhupw1360
   * @date 2017-12-12
   */
  getMyCreateCircle(params): Observable<SNSResult<CommonPageVo<SocialCircle>>> {
    const url = API.CIRCLE_MY_CREATE + "?" + this.tool.param(params);
    return this.http.get(url).map((res) => res.json());
  }

  /**
   * @description 获取全部圈子
   * @author zhupw1360
   * @date 2017-12-12
   */
  getAllCircles(params): Observable<SNSResult<CommonPageVo<SocialCircle>>> {
    const url = API.CIRCLE_GUEST_ALL + "?" + this.tool.param(params);
    return this.http.get(url).map((res) => res.json());
  }

  /**
   * @description 查询圈子所有成员
   * @author ouyqx-691
   * @date 2017-12-12
   */
  getCircleMembers(circleId: number) {
    const url: string = API.CIRCLE_MEMBERS + '?id=' + circleId;
    return this.http.get(url).map((res) => res.json());
  };

  /**
   * @description 加入圈子
   * @author zhupw1360
   * @date 2017-12-13
   */
  postJoinCircle(data) {
    const url = API.JOIN_CIRCLE;
    return this.http.postUrlencode(url, data).map((res) => res.json());
  }


  /**
   * @description 查询社區首頁信息
   * @author ouyqx-691
   * @date 2017-12-14
   */
  getCommunityIndexInfo() {
    const url: string = API.COMMUNITY_INDEX;
    return this.http.get(url).map((res) => res.json());
  };

  /**
   * @description 查询圈子帖子
   * @author ouyqx-691
   * @date 2017-12-14
   */
  getCircleFeed(params) {
    const url: string = API.CIRCLE_FEED + "?" + this.tool.param(params);
    return this.http.get(url).map((res) => res.json());
  };


  /**
   * @description 加入圈子
   * @author ouyqx-691
   * @date 2017-12-12
   */
  joinCircle(params) {
    const url: string = API.JOIN_CIRCLE;
    return this.http.postUrlencode(url, params).map((res) => res.json());
  };

  /**
   * @description 退出圈子
   * @author ouyqx-691
   * @date 2017-12-15
   */
  quitCircle(circleId: number) {
    const url: string = API.QUIT_CIRCLE + '?id=' + circleId;
    return this.http.delete(url).map((res) => res.json());
  }

  /**
   * @description 换一换热门圈子
   * @author ouyqx-691
   * @date 2017-12-15
   */
  changeHotCircle() {
    const url: string = API.CHANGE_HOT_CIRCLE;
    return this.http.get(url).map((res) => res.json());
  }

  /**
   * @description 删除圈子帖子
   * @author ouyqx-691
   * @date 2017-12-18
   */
  delFeed(feedId: number) {
    const url: string = API.CIRCLE_FEED_DEL + '?feedId=' + feedId;
    return this.http.delete(url).map((res) => res.json());
  }
}
